class Solution {
public:
    string reverseStr(string s, int k) 
    {
        int pos1 = 0,pos2= 0,n=1;
        while(n <= s.size())
        {
            if(n%(2*k) ==0)
            {
                pos2 += (k-1);
                while(pos2 > pos1)
                {
                    char tmp = s[pos1] ;
                    s[pos1] = s[pos2];
                    s[pos2] = tmp;
                    --pos2;
                    ++pos1;
                }
                pos1 = pos2 = n;
            }
            n++;
        }

        pos2 += (k-1);
        if(pos2 >= s.size())
        {
            pos2 = s.size()- 1;
        }
        while(pos2 > pos1)
        {
            char tmp = s[pos1] ;
            s[pos1] = s[pos2];
            s[pos2] = tmp;
            --pos2;
            ++pos1;
        }
        
        return s;
    }
};
